package com.project.service;

import com.project.bean.UserBean;
import com.project.dao.IUserDao;
import com.project.dao.impl.UserDaoImpl;
import com.project.server.Request;
import com.project.server.Response;
import com.project.server.Servlet;
import com.project.util.DaoFactory;
import com.project.util.WebServlet;

@WebServlet("land")
public class LoginService implements Servlet {
    private IUserDao dao = (IUserDao) DaoFactory.getDao("IUserDao");

    /**
     * 业务方法，处理登录
     * @param request 请求对象
     * @param response 响应对象
     */
    public void service(Request request, Response response){
        String userName = request.getParameter("userName");
        String password = request.getParameter("password");

        //用常量比变量，如果用变量比，容易报空指针异常
        UserBean user = dao.login(userName,password);
        if (user!=null){
            response.sendMessage("登录成功");
        }else {
            response.sendMessage("登陆失败");
        }
    }
}
